/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package hu.szitar.forum.client.ui;

import hu.szitar.forum.client.ForumClient;
import hu.szitar.forum.common.model.User;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;

/**
 *
 * @author tircsil
 */
public class ForumFrame extends JFrame{
    public ForumFrame(){
        initComponents();
    }
    
    private void initComponents() {
        
        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        GridLayout layout = new GridLayout(3, 2);
        
        JPanel main = new JPanel(layout);
        getContentPane().add(main);
        
        main.add(new JLabel("Felhasználónév"));
        final JTextField nameTf = new JTextField("username");
        main.add(nameTf);
        
        main.add(new JLabel("Jelszó"));
        JPasswordField passPf = new JPasswordField();
        main.add(passPf);
        
        JButton loginBt = new JButton("Login");
        main.add(loginBt);
        
        loginBt.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent ae) {
                User user = ForumClient.getInstance().login(nameTf.getText(), null);
                if( user != null ){
                    JOptionPane.showMessageDialog(null, "beléptél mint: "+user.getUserName(), "sikeres", JOptionPane.PLAIN_MESSAGE);
                }
                else{
                    JOptionPane.showMessageDialog(null, "hibás felhasználó név vagy jelszó", "sikertelen", JOptionPane.ERROR_MESSAGE);
                }
            }
        });

        pack();
    }
}
